/*
 * Copyright (c) 2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "cpptoc/ark_battery_info_cpptoc.h"

#include "cpptoc/ark_web_cpptoc_macros.h"

namespace OHOS::ArkWeb {

namespace {

double ARK_WEB_CALLBACK ark_battery_info_get_level(struct _ark_battery_info_t* self)
{
    ARK_WEB_CPPTOC_DV_LOG("capi struct is %{public}ld", (long)self);

    ARK_WEB_CPPTOC_CHECK_PARAM(self, 0);

    // Execute
    return ArkBatteryInfoCppToC::Get(self)->GetLevel();
}

bool ARK_WEB_CALLBACK ark_battery_info_is_charging(struct _ark_battery_info_t* self)
{
    ARK_WEB_CPPTOC_DV_LOG("capi struct is %{public}ld", (long)self);

    ARK_WEB_CPPTOC_CHECK_PARAM(self, false);

    // Execute
    return ArkBatteryInfoCppToC::Get(self)->IsCharging();
}

int ARK_WEB_CALLBACK ark_battery_info_dis_charging_time(struct _ark_battery_info_t* self)
{
    ARK_WEB_CPPTOC_DV_LOG("capi struct is %{public}ld", (long)self);

    ARK_WEB_CPPTOC_CHECK_PARAM(self, 0);

    // Execute
    return ArkBatteryInfoCppToC::Get(self)->DisChargingTime();
}

int ARK_WEB_CALLBACK ark_battery_info_charging_time(struct _ark_battery_info_t* self)
{
    ARK_WEB_CPPTOC_DV_LOG("capi struct is %{public}ld", (long)self);

    ARK_WEB_CPPTOC_CHECK_PARAM(self, 0);

    // Execute
    return ArkBatteryInfoCppToC::Get(self)->ChargingTime();
}

} // namespace

ArkBatteryInfoCppToC::ArkBatteryInfoCppToC()
{
    GetStruct()->get_level = ark_battery_info_get_level;
    GetStruct()->is_charging = ark_battery_info_is_charging;
    GetStruct()->dis_charging_time = ark_battery_info_dis_charging_time;
    GetStruct()->charging_time = ark_battery_info_charging_time;
}

ArkBatteryInfoCppToC::~ArkBatteryInfoCppToC() {}

template<>
ArkWebBridgeType ArkWebCppToCRefCounted<ArkBatteryInfoCppToC, ArkBatteryInfo, ark_battery_info_t>::kBridgeType =
    ARK_BATTERY_INFO;

} // namespace OHOS::ArkWeb
